package fr.nts.application.novadmin.database.model.common;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import fr.nts.application.novadmin.database.model.enumeration.DocumentType;
import fr.nts.framework.database.jpa.model.AJPAModel;

/**
 * Represente un document de Novadmin
 * 
 * @author sco
 * @version 1.0.0
 */
@Entity
@Table(name = "novadmin_document")
public class NovadminDocument extends AJPAModel<Long>{
    
    private static final long serialVersionUID = 1L;
    
    private static final Logger log = LoggerFactory.getLogger(NovadminDocument.class);
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, length = 10, unique = true)
    private Long id;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "document_type", nullable = false, updatable = false)
    private DocumentType documentType;
    
    @Column(name = "version", nullable = false, length = 5, updatable = false)
    private int version;
    
    @Column(name = "document_name", nullable = false, length = 255, updatable = false)
    private String documentName;
    
    @Column(name = "document_uri", nullable = false, length = 255, updatable = false)
    private String documentUri;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "date_creation", nullable = true, updatable = false)
    private Date dateCreation;
    
    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString(){
    	if(getLog().isDebugEnabled()){
	    	return new ToStringBuilder(this).append("id", id)
	    	                                .append("documentName", documentName)
	    	                                .append("documentType", documentType)
	    	                                .append("version", version)
	    	                                .append("documentUri", documentUri)
	    	                                .append("dateCreation", dateCreation)
	                                        .toString();
    	}else{
    		return super.toString();
    	}
    }


    /*
     * (non-Javadoc)
     * @see fr.nts.framework.database.jpa.model.AJPAObject#getLog()
     */
    @Override
    protected Logger getLog(){
    	return log;
    }


    // GETTER / SETTER
	public Long getId(){
		return id;
	}

	public void setId(Long id){
		this.id = id;
	}

	public DocumentType getDocumentType(){
		return documentType;
	}

	public void setDocumentType(DocumentType documentType){
		this.documentType = documentType;
	}

	public int getVersion(){
		return version;
	}

	public void setVersion(int version){
		this.version = version;
	}

	public String getDocumentName(){
		return documentName;
	}

	public void setDocumentName(String documentName){
		this.documentName = documentName;
	}

	public String getDocumentUri(){
		return documentUri;
	}

	public void setDocumentUri(String documentUri){
		this.documentUri = documentUri;
	}

	public Date getDateCreation(){
		return dateCreation;
	}

	public void setDateCreation(Date dateCreation){
		this.dateCreation = dateCreation;
	}
}